package onlinecalsys.client.view.gui;


 /****************************************************************/ 
 /*                      DeleteAppointment	                            */ 
 /*                                                              */ 
 /****************************************************************/ 
 import java.awt.*; 
 import java.awt.event.*; 
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
 import javax.swing.*; 
import javax.swing.border.*; 

import onlinecalsys.client.view.View;
 /** 
  * Summary description for DeleteAppointment 
  * 
  */ 
 public class DeleteAppointment extends JFrame 
 { 
 	// Variables declaration 
 	private JLabel jLabelAppointmentID; 
 	private JTextField jTextFieldDeleteAppointmentID; 
 	private JButton jButtonDeleteAppointment; 
 	private JPanel contentPaneAppointmentID;
	private View mainView;
	private String actualDate; 
 	
 	// End of variables declaration 
  
  
 	public DeleteAppointment(View mainView, String actualDate) 
 	{ 
 		super();
 		this.actualDate = actualDate;
 		this.mainView = mainView;
 		initializeComponent(); 
 		// 
 		// TODO: Add any constructor code after initializeComponent call 
 		// 
 		
 	// load frame logo
		BufferedImage image = null;
		try {
			URL u = this.getClass().getResource(
			"../../../../");
			File f = new File(u.getPath().replaceAll("bin/", "images/middle1.png"));
			System.out.println(f.getAbsolutePath());
			image = ImageIO.read(f);
			
			
		} catch (IOException e) {
			new Error("failed loading middle1.png");
		} catch (Exception e) {
			new Error("failed loading middle1.png");
		}
		this.setIconImage(image);
  
 		this.setVisible(true); 
 		
 	} 
 	
 	
  
 	/** 
 	 * This method is called from within the constructor to initialize the form. 
 	 * WARNING: Do NOT modify this code. The content of this method is always regenerated 
 	 * by the Windows Form Designer. Otherwise, retrieving design might not work properly. 
 	 * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder 
 	 * to retrieve your design properly in future, before revising this method. 
 	 */ 
 	private void initializeComponent() 
 	{ 
 		jLabelAppointmentID = new JLabel(); 
 		jTextFieldDeleteAppointmentID = new JTextField(); 
 		jButtonDeleteAppointment = new JButton(); 
 		contentPaneAppointmentID = (JPanel)this.getContentPane(); 
  
 		// 
 		// jLabelAppointmentID 
 		// 
 		jLabelAppointmentID.setText("ID:"); 
 		// 
 		// jTextFieldDeleteAppointmentID 
 		// 
 		jTextFieldDeleteAppointmentID.addActionListener(new ActionListener() { 
 			public void actionPerformed(ActionEvent e) 
 			{ 
 				jTextFieldDeleteAppointmentID_actionPerformed(e); 
 			} 
  
 		}); 
 		// 
 		// jButtonDeleteAppointment 
 		// 
 		jButtonDeleteAppointment.setText("Delete"); 
 		jButtonDeleteAppointment.addActionListener(new ActionListener() { 
 			public void actionPerformed(ActionEvent e) 
 			{ 
 				jButtonDeleteAppointment_actionPerformed(e); 
 			} 
  
 		}); 
 		// 
 		// contentPaneAppointmentID 
 		// 
 		contentPaneAppointmentID.setLayout(null); 
 		contentPaneAppointmentID.setBorder(new TitledBorder("Delete")); 
 		addComponent(contentPaneAppointmentID, jLabelAppointmentID, 15,23,78,18); 
 		addComponent(contentPaneAppointmentID, jTextFieldDeleteAppointmentID, 33,23,98,22); 
 		addComponent(contentPaneAppointmentID, jButtonDeleteAppointment,115,49,64,22); 
 		// 
 		// DeleteAppointment 
 		// 
 		this.setTitle("DeleteAppointment"); 
 		this.setLocation(new Point(75, 29)); 
 		this.setSize(new Dimension(200, 110)); 
 		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 
 		this.setResizable(false); 
 	} 
  
 	/** Add Component Without a Layout Manager (Absolute Positioning) */ 
 	private void addComponent(Container container,Component c,int x,int y,int width,int height) 
 	{ 
 		c.setBounds(x,y,width,height); 
 		container.add(c); 
 	} 
  
 	// 
 	// TODO: Add any appropriate code in the following Event Handling Methods 
 	// 
 	private void jTextFieldDeleteAppointmentID_actionPerformed(ActionEvent e) 
 	{ 
 		System.out.println("\njTextFieldDeleteAppointmentID_actionPerformed(ActionEvent e) called."); 
 		// TODO: Add any handling code here 
  
 	} 
  
 	private void jButtonDeleteAppointment_actionPerformed(ActionEvent e) 
 	{ 
 		try {
 			if(mainView.deleteAppointment((int) Integer.valueOf(jTextFieldDeleteAppointmentID.getText()))) {
 				mainView.updateAppoinments(actualDate);
 				dispose();
 				
 			} else {
 				
 			}
 			
 		} catch (NumberFormatException e1) {
 			new Error("Sorry, your input should be a number");
 		}
 	} 
  
 	// 
 	// TODO: Add any method code to meet your needs in the following area 
 	// 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
   
  
 //============================= Testing ================================// 
 //=                                                                    =// 
 //= The following main method is just for testing this class you built.=// 
 //= After testing,you may simply delete it.                            =// 
 //======================================================================// 
// 	public static void main(String[] args) 
// 	{ 
// 		JFrame.setDefaultLookAndFeelDecorated(true); 
// 		JDialog.setDefaultLookAndFeelDecorated(true); 
// 		try 
// 		{ 
// 			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); 
// 		} 
// 		catch (Exception ex) 
// 		{ 
// 			System.out.println("Failed loading L&F: "); 
// 			System.out.println(ex); 
// 		} 
// 		new DeleteAppointment(); 
// 	} 
 //= End of Testing = 
  
  
 } 
  
 